package cn.appsys.controller.developer;

import cn.appsys.pojo.DevUser;
import cn.appsys.service.developer.DevUserService;
import cn.appsys.tools.Constants;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class DevLoginController {
    @Resource
    private DevUserService devUserService;

    @RequestMapping("/dev/login")
    public String login() {
        return "devlogin";
    }


    @RequestMapping("/dev/dologin")
    public String dologin(String devCode, String devPassword, Model model, HttpSession session) {
        DevUser devUser = null;
        try {
            devUser = devUserService.login(devCode, devPassword);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (devUser == null) {
            model.addAttribute("error", "用户名或密码错误");
            return "devlogin";
        }
        session.setAttribute(Constants.DEV_USER_SESSION, devUser);
        return "developer/main";

    }
}
